package week03;



public class Main1 {
	void InitRational(Rational &T,int v1,int v2)
	{
		T.v1=v1;
		T.v2=v2;
	}
	Rational Add(Rational T1,Rational T2,Rational &T3)
	{

	}

	Rational Multiply(Rational T1,Rational T2,Rational &T3)
	{
		int t;
		T3.v2=T1.v2*T2.v2;
		T3.v1=T1.v1*T2.v1;
		t=Gcd(T3.v2,T3.v1);
		T3.v2/=t;
		T3.v1/=t;
	}

	int Gcd(int m,int n)
	{
		int t;
		while(m%n!=0)
		{
			t=n;
			n=m%n;
			m=t;
		}
		return n;
	}
	int GetRational(Rational T,int i,int &e)
	{
		if(i==1)
		e=T.v1;
		else
		e=T.v2;
	}


	int main() {
		int v1,v2,i,e;
		Rational T1,T2,T3;
		cin>>v1>>v2;

		InitRational(T1,v1,v2);
		cin>>v1>>v2;
		InitRational(T2,v1,v2);
		Add(T1,T2,T3);
		cout<<T3.v1<<' '<<T3.v2<<endl;
		Multiply(T1,T2,T3);
		cout<<T3.v1<<' '<<T3.v2<<endl;
		cin>>i;
		GetRational(T1,i,e);
		cout<<e<<endl;

		return 0;

	}
	
	


}
